Option Explicit

Public Sub main()
    Dim wb As Workbook
    Set wb = ActiveWorkbook

    Dim form As VBComponent

    ' ==================================================
    ' 1. 设置 form 的属性
    ' ==================================================
    Set form = wb.VBProject.VBComponents.Item("SqlFormatForm")
    With form
        .Properties("Height") = 500
        .Properties("Width") = 493
        .Properties("Caption") = "sql format"
    End With

    Dim ctrs As Controls
    Set ctrs = form.Designer.Controls

    ' ==================================================
    ' 2. 创建第一个 Frame: Alignment Config 对齐配置
    ' ==================================================
    ' 1. 生成 Frame
    Dim alignmentConfigFrame As MsForms.Frame
    Set alignmentConfigFrame = UtilsControl.createFrame(ctrs, "AlignmentConfig", _
        125, 445, 18, 12, caption:="Alignment Config", fontSize:=11)

    Dim alignmentConfigFrameCtrs As Controls
    Set alignmentConfigFrameCtrs = alignmentConfigFrame.Controls

    ' 2. 添加配置 firstConditionNeedFillSpace
    UtilsControl.createCheckBox alignmentConfigFrameCtrs, "firstConditionNeedFillSpace", _
        18, 163.5, 18, 12, caption:="firstConditionNeedFillSpace", _
        value:=True, fontSize:= 10, tabIndex:=1

    ' 3. 添加配置 multiNestAlignmentStrSizeDiff
    UtilsControl.createLabel alignmentConfigFrameCtrs, "multiNestAlignmentStrSizeDiff", _
        18, 168, 198, 15, caption:="multiNestAlignmentStrSizeDiff", fontSize:=11
    UtilsControl.createTextBox alignmentConfigFrameCtrs, "multiNestAlignmentStrSizeDiffVal", _
        18, 36, 372, 12, _
        fontSize:=11, text:=10, value:=10, tabIndex:=2

    ' 4. 添加配置 elemNestLevelPrefixSpaceCount
    UtilsControl.createLabel alignmentConfigFrameCtrs, "elemNestLevelPrefixSpaceCount", _
        18, 168, 18, 36, caption:="elemNestLevelPrefixSpaceCount", fontSize:=11
    UtilsControl.createTextBox alignmentConfigFrameCtrs, "elemNestLevelPrefixSpaceCountVal", _
        18, 36, 192, 36, _
        fontSize:=11, text:=4, value:=4, tabIndex:=3

    ' 5. 添加配置 alignmentLevel
    UtilsControl.createLabel alignmentConfigFrameCtrs, "alignmentLevel", _
        18, 90, 18, 66, caption:="alignmentLevel:", fontSize:=11
    UtilsControl.createOptionButton alignmentConfigFrameCtrs, "alignmentLevelNoAlign", _
        26, 53, 110, 60, caption:="NoAlign", value:=False, _
        fontSize:=10, tabIndex:=4, groupName:="alignmentLevel"
    UtilsControl.createOptionButton alignmentConfigFrameCtrs, "alignmentLevelInternal", _
        26, 58, 170, 60, caption:="Internal", value:=True, _
        fontSize:=10, tabIndex:=5, groupName:="alignmentLevel"
    UtilsControl.createOptionButton alignmentConfigFrameCtrs, "alignmentLevelAllLevel", _
        26, 61, 236, 60, caption:="AllLevel", value:=False, _
        fontSize:=10, tabIndex:=6, groupName:="alignmentLevel"

    ' 6. 添加配置 alignmentPosition
    UtilsControl.createLabel alignmentConfigFrameCtrs, "alignmentPosition", _
        18, 102, 18, 96, caption:="alignmentPosition:", fontSize:=11
    UtilsControl.createOptionButton alignmentConfigFrameCtrs, "alignmentPositionOperatorLeft", _
        26, 80, 126, 90, caption:="OperatorLeft", value:=False, _
        fontSize:=10, tabIndex:=7, groupName:="alignmentPosition"
    UtilsControl.createOptionButton alignmentConfigFrameCtrs, "alignmentPositionOperatorRight", _
        26, 91, 210, 90, caption:="OperatoRight", value:=True, _
        fontSize:=10, tabIndex:=8, groupName:="alignmentPosition"

    ' ==================================================
    ' 3. 创建第一个 Frame: Other Config 对齐配置
    ' ==================================================
    ' 1. 生成 Frame
    Dim otherConfigFrame As MsForms.Frame
    Set otherConfigFrame = UtilsControl.createFrame(ctrs, "OtherConfig", _
        66, 445, 18, 144, caption:="Other Config", fontSize:=11)

    Dim otherConfigFrameCtrs As Controls
    Set otherConfigFrameCtrs = otherConfigFrame.Controls

    ' 2. 添加配置 alignmentPosition
    UtilsControl.createLabel otherConfigFrameCtrs, "lineBreak", _
        18, 66, 12, 12, caption:="lineBreak:", fontSize:=11
    UtilsControl.createOptionButton otherConfigFrameCtrs, "lineBreakLf", _
        26, 34, 72, 6, caption:="Lf", value:=False, _
        fontSize:=10, tabIndex:=9, groupName:="lineBreak"
    UtilsControl.createOptionButton otherConfigFrameCtrs, "lineBreakCrLf", _
        26, 91, 114, 6, caption:="CrLf", value:=True, _
        fontSize:=10, tabIndex:=10, groupName:="lineBreak"

    ' 3. 添加配置 needSqlEndSemicolon
    UtilsControl.createCheckBox otherConfigFrameCtrs, "needSqlEndSemicolon", _
        18, 122, 12, 30, caption:="needSqlEndSemicolon", _
        value:=True, fontSize:=10, tabIndex:=11

    ' 4. 添加配置 insertColListNeedLineBreakAfterComma
    UtilsControl.createCheckBox otherConfigFrameCtrs, "insertColListNeedLineBreakAfterComma", _
        18, 210, 180, 30, caption:="insertColListNeedLineBreakAfterComma", _
        value:=True, fontSize:=10, tabIndex:=12

    ' ==================================================
    ' 4. originSql
    ' ==================================================
    ' 1. 原始 sql
    '    标题
    UtilsControl.createLabel ctrs, "originSqlTitle", _
        18, 96, 18, 222, caption:="originSql", fontSize:=10

    '   输入框
    UtilsControl.createTextBox ctrs, "originSql", _
        69, 445, 18, 246, _
        fontSize:=9, tabIndex:=13, scrollBars:=2, multiLine:=True

    ' ==================================================
    ' 5. formattedSql
    ' ==================================================
    ' 1. 转换后的 sql
    '    标题
    UtilsControl.createLabel ctrs, "formattedSqlTitle", _
        18, 96, 18, 324, caption:="formattedSql", fontSize:=9

    '   输入框
    UtilsControl.createTextBox ctrs, "formattedSql", _
        69, 445, 18, 348, _
        fontSize:=9, tabIndex:=14, scrollBars:=2, multiLine:=True

    ' ==================================================
    ' 6. 底部按钮
    ' ==================================================
    ' 1. 将sql中的名称转换为逻辑名称
    UtilsControl.createButton ctrs, "formatBtn", _
        24, 102, 348, 420, _
        caption:="format", fontSize:=9, tabIndex:=13
End Sub
